package net.magicalcloud.magicalcloud.view.viewImpl.activity;

import android.content.Context;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

import net.magicalcloud.magicalcloud.R;
import net.magicalcloud.magicalcloud.base.BaseActivity;
import net.magicalcloud.magicalcloud.presenter.LoginPresenter;
import net.magicalcloud.magicalcloud.view.ILoginView;

import butterknife.BindView;
import butterknife.OnClick;

public class LoginActivity extends BaseActivity<ILoginView,LoginPresenter> implements ILoginView {

    @BindView(R.id.et_email)
    EditText editTextEmail;
    @BindView(R.id.et_passwd)
    EditText editTextPasswd;
    @BindView(R.id.tv_result)
    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);


    }

    /**
     * 请求登录后的结果
     * @param result 状态
     */
    @Override
    public void loginResult(boolean result) {
        if(result){
            //登录成功，跳转到主页面
            startActivity(MainActivity.class,null,true);
        }else{
            toast("登录失败~");
        }
    }

    @Override
    public LoginPresenter createPresenter(){
        return new LoginPresenter();
    }

    @OnClick(R.id.btn_login)
    void login(){
        String email=editTextEmail.getText().toString();
        String passwd=editTextPasswd.getText().toString();
        mPresenter.checkUser(email,passwd);
    }

}
